package com.test.typeGame.core;

import java.awt.*;

public class TGCharObject {
    private Font font = new Font("monospace", Font.PLAIN, 30);//TimesRoman
    private Font indexNameFont = new Font("monospace", Font.PLAIN, 15);//TimesRoman
    private Color color = getRandomColorCode();
    private String indexName = "小写";
    private int index = -1;
    private char c;
    private int x = 1;
    private int y = 1;
    private int stepY = 5;
    private int stepYIndex = -1;

    public TGCharObject(){
        initC();
    }

    public Font getFont(){
        return font;
    }

    public Font getIndexNameFont(){
        return indexNameFont;
    }

    public static Color getRandomColorCode(){
        boolean bRandom = false;
        if (bRandom) {
            int r = (int) (Math.random() * 250);
            int b = (int) (Math.random() * 250);
            int g = (int) (Math.random() * 250);
            return new Color(r, b, g);
        }else {
            Color[] colors = {
                    //Color.blue,
                    Color.RED,
                    Color.CYAN,
                    Color.MAGENTA,
                    Color.ORANGE,
                    Color.PINK,
                    Color.YELLOW,
                    new Color(255,185,15)
            };
            int idx = (int) (Math.random() * colors.length);
            return colors[idx];
        }
    }

    void randomX(){
        x = (int)(Math.random()*(800-190*2)+160);
    }

    void setStepYIndex(int stepYIndex){
        this.stepYIndex = stepYIndex;
    }
    void randomStepY(){
        if (-1 == stepYIndex) {
            stepY = (int) (Math.random() * 5 + 2);
        }else{
            stepY = stepYIndex;
        }
    }
    void randomC(){
        int randomIndex = index;
        if (index == -1) {
            randomIndex = (int) (Math.random() * 3);
        }
        switch (randomIndex){
            case 1:
            {

                c = (char)(Math.random()*26+'a');
                indexName = "[小写 "+(c == 'l'?'L':c)+"]";
                indexName.toLowerCase();
                break;
            }
            case 2:
            {
                c = (char)(Math.random()*26+'A');
                indexName = "[大写 "+(c=='I'?'i':c)+"]";
                indexName = indexName.toLowerCase();
                break;
            }
            case 3:
            {
                c = (char)(Math.random()*10+'0');
                //indexName = "数字 "+c;
                indexName = "";
                break;
            }
            default:
                c = (char)(Math.random()*26+'a');
                indexName = "[小写 "+(c == 'l'?'L':c)+"]";
                indexName.toLowerCase();
        }
    }

    void initC(){
        do {
            color = getRandomColorCode();
        }while (Color.black == color);
        randomC();
        randomX();
        randomStepY();
        y = 0;
    }

    void nextC(){
        do {
            color = getRandomColorCode();
        }while (Color.black == color);
        randomC();
        randomX();
        randomStepY();
        y = 0;
    }

    void nextCWithLower(){
        nextC(1);
    }
    void nextCWithUpper(){
        nextC(2);
    }
    void nextCWithNumber(){
        nextC(3);
    }

    void nextC(int index){
        setRandomCharIndex(index);
        nextC();
    }

    void nextC(char c){
        nextC();
        this.c = c;
        this.indexName = "";
    }

    //1小写，2大写，3数字
    void setRandomCharIndex(int index){
        this.index = index;
    }

    void runDown(){
        y += stepY;
    }

    int getY(){
        return y;
    }
    int getX(){
        return x;
    }

    String getIndexName(){
        return indexName;
    }

    char getC(){
        return c;
    }

    Color getCharColor(){
        return color;
    }

    boolean bEqual(char cObj){
        return (c == cObj);
    }
}
